﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using XYAuto.Utils.Data;

namespace XYAuto.MonitorData.Chitunion.Dal
{

    //通知记录表，监听任务达到设置的预期之后，就会执行通知推送给用户，记录下通知记录
    public partial class MonitorPushNoticeLog : DataBase
    {


        public static readonly MonitorPushNoticeLog Instance = new MonitorPushNoticeLog();


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Insert(Entities.MonitorPushNoticeLog entity)
        {
            var strSql = new StringBuilder();
            strSql.Append("insert into MonitorPushNoticeLog(");
            strSql.Append("MonitorId,NoticeKey,NoticeToUser,CreateTime");
            strSql.Append(") values (");
            strSql.Append("@MonitorId,@NoticeKey,@NoticeToUser,@CreateTime");
            strSql.Append(") ");
            strSql.Append(";select SCOPE_IDENTITY()");
            var parameters = new SqlParameter[]{
                        new SqlParameter("@MonitorId",entity.MonitorId),
                        new SqlParameter("@NoticeKey",entity.NoticeKey),
                        new SqlParameter("@NoticeToUser",entity.NoticeToUser),
                        new SqlParameter("@CreateTime",entity.CreateTime),
                        };


            var obj = SqlHelper.ExecuteScalar(CONNECTIONSTRINGS, CommandType.Text, strSql.ToString(), parameters);
            return obj == null ? 0 :

                Convert.ToInt32(obj);
        }


        public int Insert(List<Entities.MonitorPushNoticeLog> list)
        {
            if (!list.Any())
            {
                return 0;
            }
            var strSql = new StringBuilder();
            strSql.Append("insert into MonitorPushNoticeLog(");
            strSql.Append("MonitorId,NoticeKey,NoticeToUser,CreateTime");
            strSql.Append(") values ");
            list.ForEach(t =>
            {
                strSql.Append($"({t.MonitorId},'{t.NoticeKey}','{t.NoticeToUser}',getdate()),");
            });

            return SqlHelper.ExecuteNonQuery(CONNECTIONSTRINGS, CommandType.Text, strSql.ToString().TrimEnd(','));
        }
    }
}

